package com.majia.lib_base.utils;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @author robin 2023-06-10 created
 */
public class BaseUtils {

    private Executor executor;
    private static BaseUtils instance;

    public static BaseUtils getInstance() {
        if (instance == null) {
            instance = new BaseUtils();
            instance.executor = Executors.newFixedThreadPool(10);
        }
        return instance;
    }

    public void runOnAsync(Runnable runnable) {
        executor.execute(runnable);
    }


    public final AppConfig appConfig = new AppConfig();

    public void loadConfig(Context context) {
        SharedPreferences sp = context.getSharedPreferences("base_config", Context.MODE_PRIVATE);
        appConfig.isFirstOpen = sp.getBoolean("isFirstOpen", true);
    }

    public void save(Context context) {
        SharedPreferences sp = context.getSharedPreferences("base_config", Context.MODE_PRIVATE);
        sp.edit()
                .putBoolean("isFirstOpen", appConfig.isFirstOpen)
                .apply();
    }
}

